#!/bin/sh

if [ -z $1 ];then
   hive_db=default
else
   hive_db=$1
fi

if [ -z $2 ];then
   create_time=`date  "+%Y-%m-%d %H-%M-%S"`
else
   create_time=$2
fi

hiveconfig=$(cat <<"EOF" /home/hdfs/parquet_shell/hive_parquet_scripts/hive.config
EOF
)

sql_suffix=$(cat <<EOF 
INSERT INTO TABLE ${hive_db}.navinfo_parquet_a203 PARTITION (part_time) SELECT latitude,longitude,originallat,originallng,height,direction,gpsdate,faultstatus,faultaddress,faultcontent,totaldrivemileage,gpsspeed,sourceaddresscnt,sourceaddress,collectdate,datalength,atmosphericpressure,atmospherictemperature,fakethrottleopening,t50status,throttleopening,dashboardspeed,totalmileage,subtotalmileage,intakeairtemperature,exhaustgastemperature,noxincontr,dpfpressurediff,noxoutcontr,urealevel,ureatemp,refertorque,egrstatus,actualoutputtorque,enginespeed,outflow,innox,outnox,inflow,watertemperature,currentgear,intakemanifoldpressure,intakemanifoldtemperature,outtakeairtemperature,realtimeoilconsumption,averagefuelconsumption,throttle1valve,eecugear,oilpressure,terminalid,'${create_time}',part_time FROM ${hive_db}.navinfo_stage_a203 distribute by part_time ;
EOF
)

sql="${hiveconfig}${sql_suffix}"
############  execute begin   ###########
hive --hiveconf "tez.queue.name=hive" -S -e "$sql"
#echo $sql
